﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Net;

namespace TMS.ServiceProvider.CapitalTransportationSolutions.ShipRite
{
    public class ProcessingRequest : ShipRiteBase
    {

        
        StringBuilder _sbRequest;

        /// <summary>
        /// Defines data format ShipRite returns. Value: XML
        /// </summary>
        public enum ProcessAction
        {
            Xml
        };

        /// <summary>
        /// Get's Request ready to be called by ProcessReates() method
        /// </summary>
        /// <param name="strUid">ID provided by CTS.</param>
        /// <param name="intFromZip">Origin zip code. 5-6 characters</param>
        /// <param name="intToZip">Destination zip code. 5-6 characters</param>
        /// <param name="dteShipDate">Shipment Date</param>
        /// <param name="shipmentClassList">Shipment Classes</param>
        /// <param name="shipmentWeightList">Shipment Weights</param>
        public ProcessingRequest(int intFromZip, int intToZip, DateTime dteShipDate, ShipmentClass[] shipmentClassList, ShipmentWeight[] shipmentWeightList)
        {
            this.FromZip = intFromZip;
            this.ToZip = intToZip;
            this.ShipDate = dteShipDate;
            this.ShipmentClasses = shipmentClassList;
            this.ShipmentWeights = shipmentWeightList;

            _sbRequest = new StringBuilder();
        }

        /// <summary>
        /// Defines data format ShipRite returns. Value: XML
        /// </summary>
        public ProcessAction Action { get; set; }


        /// <summary>
        /// Origin zip code. 5-6 characters
        /// </summary>
        public int FromZip { get; set; }

        /// <summary>
        /// Destination zip code. 5-6 characters
        /// </summary>
        public int ToZip { get; set; }

        /// <summary>
        /// Shipment Date. Format: YYYY-MM-DD
        /// </summary>
        public DateTime ShipDate
        {
            get
            {
                DateTime dteShipDate = ShipDate;
                return Convert.ToDateTime(dteShipDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.GetCultureInfo("en-US"))); 
            }
            set { ; }
        }

        /// <summary>
        /// Class of shipment. If shipment does not have a class (e.g. Truckload) use 0.  ShipRite can accommodate up to a maximum of 6 classes
        /// </summary>
        public ShipmentClass[] ShipmentClasses { get; set; }

        /// <summary>
        /// Weight of shipment.  ShipRite can accommodate up to a maximum of 6 weights.
        /// </summary>
        public ShipmentWeight[] ShipmentWeights { get; set; }


        public HttpWebResponse ProcessRates()
        {

            HttpWebRequest webRequest = WebRequest.Create(@"http://www.shipwithcts.com/cts/shiprite/rater.cfm?action=xml&UID=252&fromzip=33431&tozip=90221&shipdate=2008-12-04&class1=70&weight1=2415&LIFTGATEATPICKUP=1") as HttpWebRequest;
            HttpWebResponse response = null;
            if (webRequest != null)
            {
                webRequest.Credentials = CredentialCache.DefaultCredentials;
                response = webRequest.GetResponse() as HttpWebResponse;
                //string url = response.ResponseUri.OriginalString;

            }


            return response;
        }


    }
}
